package com.example.springbatch_itemreader_reflect;

import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;

/**
 * 自定义映射
 */
@Component("userFieldMapper")
public class UserFieldMapper implements FieldSetMapper<User> {
    @Override
    public User mapFieldSet(FieldSet fieldSet) throws BindException {

        User user = new User();
        user.setId(fieldSet.readLong("id"));   //取出并映射
        user.setAge(fieldSet.readInt("age"));
//        "province","city","area"
        user.setAddress("" + fieldSet.readString("province")
                + fieldSet.readString("city")
                + fieldSet.readString("area"));
        return user;
    }
}
